package b1.scenes.home
{
	import b1.conifg.*;
	import b1.conifg.story.FightConfig;
	import b1.controls.basic.*;
	import b1.net.*;
	import b1.players.*;
	import b1.scenes.*;
	import b1.scenes.crime.*;
	import b1.scenes.detect.*;
	import b1.scenes.fight.*;
	import b1.scenes.home.picpane.*;
	import b1.scenes.home.police.*;
	import b1.scenes.home.wanted.*;
	import b1.utils.*;
	
	import com.greensock.TimelineLite;
	import com.greensock.TweenLite;
	
	import flash.display.*;
	import flash.events.*;
	import flash.external.*;
	import flash.media.Sound;
	import flash.net.*;

	public class Home extends Sprite
	{
		public const animalPosY:int = 510;
		public var liveId:int;
		public var icons:Array;
		public var homeAnimals:Object;
		public var animalContainer:Sprite;

		private var addressNavigator:AddressNavigator;
		private var newLiveId:int;
		private var type:int;
		private var backgroundLayer:BackgroundSwitcher;
		private var backgroundImage:Sprite;
		private var animalLayer:Sprite;
		private var playerPicSwitcher:PlayerPicSwitcher;
		private var heirloomBox:HeirloomBox;
		private var soundIcon:SoundIcon;
		//以下信息用于type = 1 和 2 的情况
		private var detectiveAnimal:AnimalInfo;
		private var arrestTagertAnimal:AnimalInfo;
		private var battleCase:BattleCaseInfo;
		private var showHeirlooms:Array;
		private var hasHeirloomBox:Boolean;
		
		//type, 0, 正常进入；1, 逮捕（正确判断）；2, 逮捕（错误判断）; 3, 作案; 4, 探案
		public function Home(liveId:int, type:int = 0, detectiveAnimal:AnimalInfo = null, arrestTagertAnimal:AnimalInfo = null, battleCase:BattleCaseInfo = null)
		{
			super();
			this.liveId = liveId;
			this.newLiveId = liveId;
			this.type = type;
			this.detectiveAnimal = detectiveAnimal;
			this.arrestTagertAnimal = arrestTagertAnimal;
			this.battleCase = battleCase;
			this.icons = new Array();
			this.hasHeirloomBox = false;
			//背景层
			backgroundLayer = new BackgroundSwitcher(new HomeBackground(0));
			backgroundLayer.mouseEnabled = false;
			backgroundLayer.mouseChildren = false;
			//天空
			var sky:Sky = new Sky(backgroundLayer);
			addChild(sky);
			addChild(backgroundLayer);
			//动物活动层
			animalLayer = new Sprite();
			addChild(animalLayer);
			//如果是人人用户，加载用户头像
			playerPicSwitcher = new PlayerPicSwitcher();
			playerPicSwitcher.x = 5;
			playerPicSwitcher.y = 5;
			this.addChild(playerPicSwitcher);
			//加载门牌
			addressNavigator = new AddressNavigator(0);
			addressNavigator.x = (BFont.stageWidth - addressNavigator.width) / 2;
			addressNavigator.y = 10;
			addChild(addressNavigator);
			//加载任务
			var TaskIcon:Class = ResourceHelper.getInstance().getClassByName("TaskIcon");
			var taskIcon:BasicIcon = new BasicIcon(TaskIcon, "任务", 1, true);
			taskIcon.x = 10;
			taskIcon.y = 200;
			addChild(taskIcon);
			taskIcon.addEventListener(MouseEvent.CLICK, onTaskIconClick);
			icons.push(taskIcon);
			var me:PlayerInfo = PlayerInfoHelper.getInstance().players[PlayerInfoHelper.getInstance().userId];
			if (type != 1 && type != 2 && me.accomplishedTaskId + 1 < Config.taskConfigs.length)
			{
				var taskConfig:TaskConfig = Config.taskConfigs[me.accomplishedTaskId + 1];
				if (taskConfig.shineTaskIconFlag)
					taskIcon.startShine();
			}
			//加载警署
			var PoliceStation:Class = ResourceHelper.getInstance().getClassByName("PoliceStation");
			var policeStationIcon:BasicIcon = new BasicIcon(PoliceStation, "警署", 1, true);
			policeStationIcon.x = BFont.stageWidth - policeStationIcon.width - 10;
			policeStationIcon.y = 10;
			addChild(policeStationIcon);
			policeStationIcon.addEventListener(MouseEvent.CLICK, onPoliceStationIconClick);
			icons.push(policeStationIcon);
			//加载探案
			var DetectIcon:Class = ResourceHelper.getInstance().getClassByName("DetectIcon");
			var detectIcon:BasicIcon = new BasicIcon(DetectIcon, "探案", 1, true);
			detectIcon.x = policeStationIcon.x - policeStationIcon.width - 15;
			detectIcon.y = policeStationIcon.y;
			addChild(detectIcon);
			detectIcon.addEventListener(MouseEvent.CLICK, onDetectIconClick);
			icons.push(detectIcon);
			//加载作案
			var CrimeIcon:Class = ResourceHelper.getInstance().getClassByName("CrimeIcon");
			var crimeIcon:BasicIcon = new BasicIcon(CrimeIcon, "作案", 1, true);
			crimeIcon.x = detectIcon.x - detectIcon.width - 15;
			crimeIcon.y = detectIcon.y;
			addChild(crimeIcon);
			crimeIcon.addEventListener(MouseEvent.CLICK, onCrimeIconClick);
			icons.push(crimeIcon);
			//加载商店
			var StoreIcon:Class = ResourceHelper.getInstance().getClassByName("StoreIcon");
			var storeIcon:BasicIcon = new BasicIcon(StoreIcon, "商店", 1, true);
			storeIcon.x = policeStationIcon.x;
			storeIcon.y = policeStationIcon.y + policeStationIcon.height + 10;
			addChild(storeIcon);
			storeIcon.addEventListener(MouseEvent.CLICK, onStoreIconClick);
			icons.push(storeIcon);
			//加载通缉榜
			var WantedIcon:Class = ResourceHelper.getInstance().getClassByName("WantedIcon");
			var wantedIcon:BasicIcon = new BasicIcon(WantedIcon, "榜单", 1, true);
			wantedIcon.x = storeIcon.x;
			wantedIcon.y = storeIcon.y + storeIcon.height + 10;
			addChild(wantedIcon);
			wantedIcon.addEventListener(MouseEvent.CLICK, onWantedIconClick);
			icons.push(wantedIcon);
			//加载节日任务
			if (me.accomplishedFestivalTaskId + 1 < Config.festivalTaskConfigs.length)
			{
				var festivalTaskConfig:TaskConfig = Config.festivalTaskConfigs[me.accomplishedFestivalTaskId + 1];
				var FestivalTaskIcon:Class = ResourceHelper.getInstance().getClassByName(festivalTaskConfig.iconImage);
				var festivalTaskIcon:BasicIcon = new BasicIcon(FestivalTaskIcon, "月饼", 1, true, false, festivalTaskConfig.textColor);
				festivalTaskIcon.x = 10;
				festivalTaskIcon.y = 280;
				festivalTaskIcon.startShine(festivalTaskConfig.shineColor);
				addChild(festivalTaskIcon);
				icons.push(festivalTaskIcon);
				festivalTaskIcon.addEventListener(MouseEvent.CLICK, onFestivalTaskIconClick);
			}
			//加载声音图标
			soundIcon = new SoundIcon();
			soundIcon.x = BFont.stageWidth - soundIcon.width - 15;
			soundIcon.y = 300;
			addChild(soundIcon);
			//紧急出口图标
			var exitIcon:ExitIcon = new ExitIcon();
			exitIcon.x = soundIcon.x;
			exitIcon.y = soundIcon.y + soundIcon.height + 10;
			addChild(exitIcon);
			//加载底部图标条
			BottomNavigator.getInstance().open(this);
			//加载动物
			ServerHelper.getInstance().switchHome(liveId, liveId, onSwitchHomeComplete);
			showHeirlooms = new Array();
			//播放音效
			var SoundBird:Class = ResourceHelper.getInstance().getClassByName("SoundBird" + Clock.currentSeason);
			var sound:Sound = new SoundBird();
			sound.play(0, 8); 
		}
		
		public function switchLiveId(newLiveId:int, force:Boolean = false):void
		{
			if (force || newLiveId != this.liveId)
			{
				this.newLiveId = newLiveId;
				if (newLiveId < 0)
				{
					var playerInfo:PlayerInfo = PlayerInfoHelper.getInstance().players[newLiveId] as PlayerInfo;
					if (playerInfo != null)
						onSwitchHomeComplete("success", this.liveId, newLiveId, playerInfo.name, 0, playerInfo.homeIndex, playerInfo.liveAnimals);
					else
						onSwitchHomeComplete("Id not exist", -1, -1, null, -1, -1, null);
				}
				else
				{
					ServerHelper.getInstance().switchHome(liveId, newLiveId, onSwitchHomeComplete);
				}
			}
		}
		
		//任务按钮响应
		private function onTaskIconClick(event:MouseEvent):void
		{
			if (SceneContainer.getInstance().mouseDisableFlag && !SceneContainer.getInstance().checkOnlyMousePosition(event.currentTarget))
				return;
			var me:PlayerInfo = PlayerInfoHelper.getInstance().players[PlayerInfoHelper.getInstance().userId];
			if (me.accomplishedTaskId + 1 < Config.taskConfigs.length)
			{
				var taskConfig:TaskConfig = Config.taskConfigs[me.accomplishedTaskId + 1];
				TaskDialog.getInstance().open(this, taskConfig);
				//添加新手导引
				if (SceneContainer.getInstance().step == 7)					
					SceneContainer.getInstance().addStep();
			}
		}
		
		//节日任务按钮响应
		private function onFestivalTaskIconClick(event:MouseEvent):void
		{
			if (SceneContainer.getInstance().mouseDisableFlag && !SceneContainer.getInstance().checkOnlyMousePosition(event.currentTarget))
				return;
			var me:PlayerInfo = PlayerInfoHelper.getInstance().players[PlayerInfoHelper.getInstance().userId];
			if (me.accomplishedFestivalTaskId + 1 < Config.festivalTaskConfigs.length)
			{
				var festivalTaskConfig:TaskConfig = Config.festivalTaskConfigs[me.accomplishedFestivalTaskId + 1];
				TaskDialog.getInstance().open(this, festivalTaskConfig);
			}
		}
		
		private function onStoreIconClick(event:MouseEvent):void
		{
			if (SceneContainer.getInstance().mouseDisableFlag && !SceneContainer.getInstance().checkOnlyMousePosition(event.currentTarget))
				return;
			Store.getInstance().open(this);
		}
		
		private function onDetectIconClick(event:MouseEvent):void
		{
			if (SceneContainer.getInstance().mouseDisableFlag && !SceneContainer.getInstance().checkOnlyMousePosition(event.currentTarget))
				return;
			DetectDiaglog.getInstance().open(this);
		}
		
		public function onWantedIconClick(event:MouseEvent):void
		{
			if (SceneContainer.getInstance().mouseDisableFlag && !SceneContainer.getInstance().checkOnlyMousePosition(event.currentTarget))
				return;
			WantedTab.getInstance().open(this);
		}
		
		private function onCrimeIconClick(event:MouseEvent):void
		{
			if (SceneContainer.getInstance().mouseDisableFlag && !SceneContainer.getInstance().checkOnlyMousePosition(event.currentTarget))
				return;
			CrimeDialog.getInstance().open(this);
		}
		
		private function onPoliceStationIconClick(event:MouseEvent):void
		{
			if (SceneContainer.getInstance().mouseDisableFlag && !SceneContainer.getInstance().checkOnlyMousePosition(event.currentTarget))
				return;
			PoliceStation.getInstance().open(this);
		}
		
		private function onSwitchHomeComplete(result:String, oldLiveId:int, newLiveId:int, newLiveUserName:String, newLiveRenrenId:int, newLiveHomeIndex:int, newAnimalIds:Array):void
		{
			if (result == "Id not exist")
			{
				var msgBox:MessageBox = new MessageBox("该住址不存在！");
				msgBox.x = (BFont.stageWidth - msgBox.width) / 2;
				msgBox.y = (BFont.stageHeight - msgBox.height) / 2;
				addChild(msgBox);
				return;
			}
			if (result != "success")
				return;
			var players:Object = PlayerInfoHelper.getInstance().players;
			this.newLiveId = newLiveId;
			if (hasHeirloomBox && heirloomBox != null &&  heirloomBox.parent != null)
			{
				heirloomBox.parent.removeChild(heirloomBox);
			}
			//切换背景
			backgroundLayer.switchBackground(new HomeBackground(newLiveHomeIndex), 2);
			//切换动物
			this.liveId = this.newLiveId;
			addressNavigator.numBox.text = (liveId + AddressNavigator.baseLiveNum).toString();
			if (animalContainer != null)
			{
				animalLayer.removeChild(animalContainer);
			}
			homeAnimals = new Array();
			animalContainer = new Sprite();
			animalLayer.addChild(animalContainer);
			//加载对话框
			if (type == 3)
			{
				CrimeDialog.getInstance().open(this);
			}
			else if (type == 4)
			{
				DetectDiaglog.getInstance().open(this);
			}
			//普通玩家
			if (this.newLiveId > 0)
			{
				//切换用户图片
				var newLivePlayer:PlayerInfo = PlayerInfoHelper.getInstance().players[newLiveId];
				playerPicSwitcher.switchPlayer(newLivePlayer);
				//加载传家宝箱
				heirloomBox = new HeirloomBox(players[newLiveId]);	
				heirloomBox.x = 500;
				heirloomBox.y = 520 - heirloomBox.height;
				animalContainer.addChild(heirloomBox);
				hasHeirloomBox = true;
			}
			//加载传家宝
			refreshHeirlooms();
			//不在故事模式下面的时候，可能突然跳出boss
			if (!StoryHelper.getInstance().storyModeFlag)
			{
				appearBoss(newLiveHomeIndex);
			}
			//加载动物
			var foundTargetFlag:Boolean = false;
			for (var i:int = 0; i < newAnimalIds.length; i++)
			{
				var animalId:int = parseInt(newAnimalIds[i]);
				var animalInfo:AnimalInfo = PlayerInfoHelper.getInstance().animals[animalId];
				if (animalInfo.liveId == this.liveId)
				{
					var homeAnimal:HomeAnimal = new HomeAnimal(animalId, newLiveHomeIndex);
					homeAnimal.x = Math.random() * 600 + 50;
					homeAnimal.y = homeAnimal.adjustPosY();
					animalContainer.addChild(homeAnimal);
					homeAnimals[animalId] = homeAnimal;
					if (type == 1 || type == 2)
					{
						//如果找到逮捕的对象
						if (arrestTagertAnimal != null && arrestTagertAnimal.id == animalId)
						{
							//开始播放逮捕的动画
							foundTargetFlag = true;
							var rejectFlag:Boolean;
							if (type == 1)
							{
								rejectFlag = false;
							}
							else
							{
								rejectFlag = true;
							}
							var arrestDialog:ArrestWarrantDialog = new ArrestWarrantDialog(this.detectiveAnimal, this.arrestTagertAnimal, rejectFlag, battleCase.caseBones, 0, battleCase, 0, null);
							arrestDialog.x = (BFont.stageWidth - arrestDialog.width) / 2;
							arrestDialog.y = 80;
							addChild(arrestDialog);
						}
					}
				}	
			}
		
			//如果没有找到逮捕对象
			if (!foundTargetFlag)
			{
				//正确判断真实罪犯
				if (type == 1)
				{
					var wantedDialog:WantedPostDialog = new WantedPostDialog(this.detectiveAnimal, this.arrestTagertAnimal, battleCase);
					wantedDialog.x = BFont.stageWidth / 2;
					wantedDialog.y = 300;
					addChild(wantedDialog);
				}
				//错误判断
				else if (type == 2)
				{
					
				}
			}
			//重置类型
			this.type = 0;
			this.detectiveAnimal = null;
			this.arrestTagertAnimal = null;
			this.battleCase = null;
			//触发故事
			if (StoryHelper.getInstance().storyModeFlag)
			{
				StoryHelper.getInstance().clearElementsOnSwitchHome();
				StoryHelper.getInstance().nextStep();
			}
			//添加新手导引
			if (SceneContainer.getInstance().step == 1)
			{
				welcomeFirstEntry();
				SceneContainer.getInstance().addStep();
			}
		}
		
		//加载可能出现的boss
		private function appearBoss(newLiveHomeIndex:int):void
		{
			var virtualPlayer:VirtualPlayerConfig = PlayerInfoHelper.getInstance().players[this.newLiveId] as VirtualPlayerConfig;
			var randomNumber:Number;
			if (virtualPlayer != null)
			{
				for(var j:String in virtualPlayer.bossesAppear)
				{
					randomNumber = Math.random();
					var bossAppearInfo:Array = virtualPlayer.bossesAppear[j] as Array;
					if (randomNumber < Number(bossAppearInfo[1]))
					{
						var bossId:int = parseInt(j);
						var animal:HomeAnimal = new HomeAnimal(bossId, newLiveHomeIndex);
						animal.stopWalk();
						animalContainer.addChild(animal);
						animal.x = 0;
						animal.y = -200;
						var words:String = bossAppearInfo[2];
						TweenLite.to(animal, 3, {x:300, y:500, onComplete:animal.reachPositionOnComplete, onCompleteParams:[words]});
						break;
					}
				}
			}
		}
		
		public function welcomeFirstEntry():void
		{
			var messageBox:MessageBoxWithIcon = new MessageBoxWithIcon("多谢 self 探长阁下的及时救助，不然我就没命了。\n这是我祖传的玛普尔套装，请探长收下。", "id:-5", Config.assistantName);
			messageBox.x = BFont.stageWidth / 2;
			messageBox.y = BFont.stageHeight / 2;
			addChild(messageBox);
		}
		
		public function startRemovePrisonMovie(animalId:int):void
		{
			var homeAnimal:HomeAnimal = homeAnimals[animalId];
			if (homeAnimal != null)
			{
				homeAnimal.removePrisonCage();
			}
		}
		
		public function refreshHeirlooms():void
		{
			var popHeirloom:Heirloom;
			while (showHeirlooms.length != 0)
			{
				popHeirloom = showHeirlooms.pop();
				popHeirloom.stopMove();
				animalLayer.removeChild(popHeirloom);
			}
			var players:Object = PlayerInfoHelper.getInstance().players;
			for (var heirIndex:String in players[liveId].heirlooms)
			{
				var heirloom:Heirloom = players[liveId].heirlooms[heirIndex];
				if (heirloom != null)
				{
					heirloom.x = Math.round(Math.random() * 200) + 200;
					heirloom.y = 100;
//					heirloom.height = 80;
//					heirloom.scaleX = heirloom.scaleY;
					heirloom.startMove();
					animalLayer.addChild(heirloom);
					showHeirlooms.push(heirloom);
				}
			}
		}
		
//		public function refreshHeirlooms(loseHeirloomId:String, rightPlayerId:int):void
//		{
//			if (loseHeirloomId == null) return;
//			//加载传家宝
//			var players:Object = PlayerInfoHelper.getInstance().players;
//			for (var heirIndex:String in (players[newLiveId] as PlayerInfo).heirlooms)
//			{
//				var heirloom:Heirloom = players[newLiveId].heirlooms[heirIndex];
//			    if (heirloom != null && heirloom.originalOwnerPlayerId == parseInt(loseHeirloomId) && this.liveId == PlayerInfoHelper.getInstance().userId)
//				{
//					heirloom.x = Math.round(Math.random() * 200) + 200;
//					heirloom.y = 100;
//					heirloom.height = 80;
//					heirloom.scaleX = heirloom.scaleY;
//					heirloom.startMove();
//					animalLayer.addChild(heirloom);
//					showHeirlooms.push(heirloom);
//				}
//			}
//			if (newLiveId == rightPlayerId)
//			{
//				for (var i:int = 0; i < showHeirlooms.length; i++)
//				{
//					if ((showHeirlooms[i] as Heirloom).originalOwnerPlayerId == parseInt(loseHeirloomId))
//					{
//						(showHeirlooms[i] as Heirloom).visible = false;
//					}
//				}
//			}
//		}
		
		public function startArrestAnimalMovie(animalId:int):void
		{
			var homeAnimal:HomeAnimal = homeAnimals[animalId];
			if (homeAnimal != null)
			{
				var animalInfo:AnimalInfo = PlayerInfoHelper.getInstance().animals[animalId];
				animalInfo.wantedBones = 0;
				animalInfo.timeToClose = 0;
				homeAnimal.removeHandcuffs();
				var PoliceCar:Class = ResourceHelper.getInstance().getClassByName("PoliceCar");
				var policeCar:Sprite = new PoliceCar();
				policeCar.height = 80;
				policeCar.scaleX = policeCar.scaleY;
				policeCar.x = 800;
				policeCar.y = animalPosY - policeCar.height;
				addChild(policeCar);
				var myTimeline:TimelineLite = new TimelineLite();
				myTimeline.append(new TweenLite(policeCar, (800 - homeAnimal.x) / 150, {x:homeAnimal.x, y:homeAnimal.y - policeCar.height, onComplete: homeAnimal.addPrisonCage}));
				myTimeline.append(new TweenLite(policeCar, (homeAnimal.x + policeCar.width)/ 150, {x:-policeCar.width, y:animalPosY - policeCar.height, onComplete:onArrestAnimalMovieComplete, onCompleteParams:[policeCar]}));
			}
		}
		
		public function onArrestAnimalMovieComplete(policeCar:Sprite):void
		{
			removeChild(policeCar);
		}
		
		public function startFight(rightPlayerId:int, rightAnimals:Array):void
		{
			var leftPlayer:PlayerInfo = PlayerInfoHelper.getInstance().players[PlayerInfoHelper.getInstance().userId];
			var leftAnimalInfo:AnimalInfo = PlayerInfoHelper.getInstance().animals[leftPlayer.ownAnimals[0]];

			var msgBox:MessageBox;
			//加载战斗场面
			if (leftAnimalInfo.liveId != leftAnimalInfo.ownerId)
			{
				msgBox = new MessageBox("你现在寄人篱下，不能作案……");
				msgBox.x = (BFont.stageWidth - msgBox.width) / 2;
				msgBox.y = (BFont.stageHeight - msgBox.height) / 2;
				addChild(msgBox);
			}
			else if (leftAnimalInfo.timeToGetFree > ServerHelper.getInstance().now())
			{
				msgBox = new MessageBox("你现在还未刑满释放，不能作案……");
				msgBox.x = (BFont.stageWidth - msgBox.width) / 2;
				msgBox.y = (BFont.stageHeight - msgBox.height) / 2;
				addChild(msgBox);
			}
			else
			{
				if (rightAnimals.length > 0)
				{
					//虚拟玩家
					if (rightAnimals[0] < 0)
					{	
						var rightAnimal:VirtualAnimalConfig = PlayerInfoHelper.getInstance().animals[rightAnimals[0]];
						var fight:Fight = new Fight(leftPlayer.id, rightPlayerId, leftPlayer.ownAnimals, rightAnimals, onEndFightCallBack, rightAnimal.fightConfig);
						SceneContainer.getInstance().loadScene(fight);
					}
					//真实玩家
					else
					{
						ServerHelper.getInstance().startFight(leftPlayer.id, rightPlayerId, [leftAnimalInfo.id], rightAnimals, onStartFightComplete);
					}
				}
				else
				{
					msgBox = new MessageBox("人去楼空家徒四壁，没有作案的价值……");
					msgBox.x = (BFont.stageWidth - msgBox.width) / 2;
					msgBox.y = (BFont.stageHeight - msgBox.height) / 2;
					addChild(msgBox);
				}
			}
		}
		
		private function onStartFightComplete(result:String, leftPlayerId:int, rightPlayerId:int, leftAnimals:Array, rightAnimals:Array):void
		{
			var leftPlayer:PlayerInfo = PlayerInfoHelper.getInstance().players[leftPlayerId];
			var rightPlayer:PlayerInfo = PlayerInfoHelper.getInstance().players[rightPlayerId];
			//成功加载战斗
			if (result == "success")
			{
				var fight:Fight = new Fight(leftPlayerId, rightPlayerId, leftAnimals, rightAnimals, onEndFightCallBack);
				SceneContainer.getInstance().loadScene(fight);
			}
			//对方还在上次战斗的恢复中
			else
			{
				var rightAnimalInfo:AnimalInfo = PlayerInfoHelper.getInstance().animals[rightAnimals[0]];
				var msgBox:MessageBox = new MessageBox(rightAnimalInfo.ownerName + " 的 " + rightAnimalInfo.animalName + " 还在上次战斗的恢复中……");
				msgBox.x = (BFont.stageWidth - msgBox.width) / 2;
				msgBox.y = (BFont.stageHeight - msgBox.height) / 2;
				addChild(msgBox);
			}
		}
		
		private function onEndFightCallBack(leftPlayerId:int, rightPlayerId:int, winnerAnimalId:int, loserAnimalId:int, caseBones:int, 
			loseHeirloomId:int, animalCluesDrop:Object, fightConfig:FightConfig, newHonours:Object):void
		{
			//刷新声音图标
			soundIcon.refresh();
			var me:PlayerInfo = PlayerInfoHelper.getInstance().players[PlayerInfoHelper.getInstance().userId];
			var msgBox:MessageBox;
			if (loseHeirloomId >= 0)
			{
				var leftPlayer:PlayerInfo = PlayerInfoHelper.getInstance().players[leftPlayerId];
				var rightPlayer:PlayerInfo = PlayerInfoHelper.getInstance().players[rightPlayerId];
				leftPlayer.heirlooms[loseHeirloomId] = rightPlayer.heirlooms[loseHeirloomId]; 
				rightPlayer.heirlooms[loseHeirloomId] = null;
				refreshHeirlooms();
			}
			//新装备勋章
			if (newHonours != null)
			{
        		var honorBox:HonourBox = new HonourBox(newHonours);
        		honorBox.x = (BFont.stageWidth - honorBox.width) / 2;
        		honorBox.y = (BFont.stageHeight - honorBox.height) / 2;
        		SceneContainer.getInstance().currentScene.addChild(honorBox);
			}
			else
			{
				//成功作案
				if (winnerAnimalId == parseInt(me.ownAnimals[0]))
				{
					var hasClueFlag:Boolean = false;
					for (var clueIndex:String in animalCluesDrop)
					{
						hasClueFlag = true;
						break;
					}
					if (hasClueFlag)
					{
						ServerHelper.getInstance().addCase(winnerAnimalId, loserAnimalId, caseBones, animalCluesDrop, null, loseHeirloomId, onAddCaseComplete);
					}
					else
					{
						msgBox = new MessageBox("完美作案而没有留下任何线索，你是犯罪天才！");
						msgBox.x = (BFont.stageWidth - msgBox.width) / 2;
						msgBox.y = (BFont.stageHeight - msgBox.height) / 2;
						addChild(msgBox);
					}
				}
				//作案未遂
				else
				{
					msgBox = new MessageBox("作案未遂！真没想到你连犯罪都没有天赋……");
					msgBox.x = (BFont.stageWidth - msgBox.width) / 2;
					msgBox.y = (BFont.stageHeight - msgBox.height) / 2;
					addChild(msgBox);
				}
			}
			//动物技能点图标显示更新
			if (homeAnimals[me.ownAnimals[0]] != null)
				homeAnimals[me.ownAnimals[0]].setSkillPointIconVisibility();
		}
		
		private function onAddCaseComplete(result:String, battleCase:BattleCaseInfo):void
		{
			if (result == "success")
			{
				var caseEstablishDialog:CaseEstablishDialog = new CaseEstablishDialog(battleCase);
				caseEstablishDialog.x = BFont.stageWidth / 2;
				caseEstablishDialog.y = BFont.stageHeight / 2;
				addChild(caseEstablishDialog);
			}
		}
	}
}